load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
    name = "logpb",
    srcs = [
        "event.go",
        "severity.go",
        "test_utils.go",
        ":gen-json-encode-generated-go",  # keep
    ],
    embed = [":logpb_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/util/log/logpb",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/util/jsonbytes",  # keep
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_gogo_protobuf//jsonpb",  # keep
    ],
)

proto_library(
    name = "logpb_proto",
    srcs = [
        "event.proto",
        "log.proto",
    ],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = ["@com_github_gogo_protobuf//gogoproto:gogo_proto"],
)

go_proto_library(
    name = "logpb_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/util/log/logpb",
    proto = ":logpb_proto",
    visibility = ["//visibility:public"],
    deps = ["@com_github_gogo_protobuf//gogoproto"],
)

exports_files(
    [
        "log.proto",
        "event.proto",
    ],
    visibility = ["//visibility:public"],
)

genrule(
    name = "gen-json-encode-generated-go",
    srcs = ["event.proto"],
    outs = ["json_encode_generated.go"],
    cmd = """
    $(location //pkg/util/log/eventpb/eventpbgen:eventpbgen) \
        --package=logpb \
        json_encode_go \
        $(location event.proto) \
        >$(location json_encode_generated.go)
    """,
    tools = [
        "//pkg/util/log/eventpb/eventpbgen",
    ],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)
